package tpf.designer.pattern.course5.structure_pattern2.flyweight_13.coffeeshop;

import org.apache.log4j.Logger;
import org.junit.Test;

public class Client {

    public static final Logger LOGGER = Logger.getLogger(Client.class);
    private static Order[] flavors = new Flavor[100];
    private static int ordersMade = 0;
    private static FlavorFactory flavorFactory;
    private static FlavorFactorySingleton flavorFactorySingleton;

    /**
     * 静态方法： 提供一杯咖啡
     * @param aFlavor
     */
    private static void takeOrders(String aFlavor){
//        flavors[ordersMade++] = flavorFactory.getOrder(aFlavor);
        flavors[ordersMade++] = flavorFactorySingleton.getOrder(aFlavor);
    }

    @Test
    public void testCoffee(){
//        flavorFactory = new FlavorFactory();
        flavorFactorySingleton = FlavorFactorySingleton.getInstance();

        takeOrders("ba coffee");
        takeOrders("ba coffee");
        takeOrders("ba coffee");
        takeOrders("ba coffee");
        takeOrders("ba coffee");
        takeOrders("ba1 coffee");
        takeOrders("ba coffee");
        takeOrders("ba coffee");
        takeOrders("ba coffee");
        takeOrders("ba coffee");
        takeOrders("ba coffee");
        takeOrders("ba coffee");
        takeOrders("ba coffee");

        for (int i = 0; i < ordersMade; i++){
            flavors[i].serve(new Table(i));
        }
//        LOGGER.info(flavorFactory.getTotalFlavorsMade());
        LOGGER.info(flavorFactorySingleton.getTotalFlavorsMade());

    }
}
